% 定义函数 f(x)
f = @(x) 1./(1 + x.^2);

% 定义插值点的函数
compute_xi = @(n) -5 + 10.*(0:n)./n;

% 主程序
x = linspace(-5, 5, 1000);
y_exact = f(x);

hold on
plot(x, y_exact, 'k-', 'LineWidth', 2)

% n 值列表
n_values = [2, 4, 6, 8];

for n = n_values
    xi = compute_xi(n);
    yi = f(xi);
    y_interp = runge_functionsB(xi, yi, x);
    plot(x, y_interp, '--', 'LineWidth', 1.5)
end

legend('Exact', 'n=2', 'n=4', 'n=6', 'n=8')
title('Runge Phenomenon')
xlabel('x')
ylabel('y')
hold off
